<?xml version="1.0" encoding="utf-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
  <start>
    <element name="library">
      <oneOrMore>
        <ref name="book-element"/>
      </oneOrMore>
    </element>
  </start>
  <define name="author-element">
    <element name="author">
      <grammar>
        <start>
          <attribute name="id"/>
        </start>
        <start combine="interleave">
          <group>
            <ref name="name-element"/>
            <ref name="born-element"/>
            <optional>
              <ref name="dead-element"/>
            </optional>
          </group>
        </start>
        <define name="name-element">
          <element name="name">
            <text/>
          </element>
        </define>
        <define name="born-element">
          <element name="born">
            <text/>
          </element>
        </define>
        <define name="dead-element">
          <element name="dead">
            <text/>
          </element>
        </define>
      </grammar>
    </element>
  </define>
  <define name="book-element">
    <element name="book">
      <attribute name="id"/>
      <attribute name="available"/>
      <ref name="isbn-element"/>
      <ref name="title-element"/>
      <zeroOrMore>
        <ref name="author-element"/>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="character-element"/>
      </zeroOrMore>
    </element>
  </define>
  <define name="character-element">
    <grammar>
      <start>
        <element name="character">
          <attribute name="id"/>
          <ref name="name-element"/>
          <ref name="born-element"/>
          <ref name="qualification-element"/>
        </element>
      </start>
      <define name="name-element">
        <element name="name">
          <text/>
        </element>
      </define>
      <define name="born-element">
        <element name="born">
          <text/>
        </element>
      </define>
      <define name="qualification-element">
        <element name="qualification">
          <text/>
        </element>
      </define>
    </grammar>
  </define>
  <define name="isbn-element">
    <element name="isbn">
      <text/>
    </element>
  </define>
  <define name="title-element">
    <element name="title">
      <attribute name="xml:lang"/>
      <text/>
    </element>
  </define>
</grammar>
